const url = new URLSearchParams(window.location.href);
// 请求前缀
const prefix = this.pageObj.getVariables().find(v => v.name === "environmentType")?.value;
let detail = JSON.parse(url && url.get('personDetail') || '{}');

function basePost(url, params) {
    const option = {
        method: 'POST',
        headers: { 'Content-type': 'application/json' },
        body: JSON.stringify(params),
    }
    return fetch(url, option).then(res => res.json())
}

// const whether_process = this.pageObj.getVariables().find(v => v.name === 'whether_process')?.value || 0
basePost(`/${prefix}Event/drillPlanInfo/lastPlan`, { whetherProcess: 0 })
    .then(({ success, result}) => {
        console.log('res', { success, result})
        if(success) {
            const data = {}

            while (result.length) {
                const item = result.shift();
                const code = `${item.projectCode}`
                if (!data[code]) data[code] = {
                    title: item.projectName,
                    id: `all-${item.projectId || ''}`,
                    uniqueKey: `all-${item.projectId || ''}`,
                    count: 0,
                    children: []
                }
                if (!data[code].title) {
                    data[code].title = item.projectName
                }
                if (data[code].id === 'all-') {
                    data[code].id = `all-${item.projectId || ''}`
                }

                data[code].children.push(item)
                data[code].count += 1;
                data[code].eventList = data[code].children
            }

            console.log('演练列表 - 最新 30 条', data)
            this.widgetObj.setData([{ data: Object.values(data) }])
            this.widgetObj.render()
        }
    }).catch(e => {
    console.error('获取最新', e)
})